package view;

import java.awt.Dimension;
import java.util.List;
import java.util.Vector;

import javax.swing.GroupLayout;
//import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import model.bean.Department;
import model.dao.DepartmentDAO;

public class PnlUserDepartmentList extends JPanel {
	
	private JScrollPane spnlRoleData;
    private JScrollPane spnlRoleData1;
    private JTable tblData;
    // End of variables declaration//GEN-END:variables
    DefaultTableModel tblModel = new DefaultTableModel();
    
	    /** create form RoleEmployeeUIPanel */
	    public PnlUserDepartmentList() {
	        initComponents();
	        
	        loadTableData();
	    }


	    private void loadTableData() {
	       // try {
	            List<Department> departmentList = DepartmentDAO.selectAllDepartment();
	            tblModel.addColumn("Department id");
	            tblModel.addColumn("Department name");
	            tblModel.addColumn("Number Employee");
	          for (Department department : departmentList) {
	                Vector<String> row = new Vector<String>();
	                row.addElement(String.valueOf(department.getDepartmentId()));
	                row.addElement(department.getDepartmentName());
	                row.addElement(String.valueOf(department.getNumberOfEmployees()));
	                  tblModel.addRow(row);
	            }
	            tblData.setModel(tblModel);
//	        } catch (ClassNotFoundException ex) {
//	            JOptionPane.showMessageDialog(null,
//	                    "",
//	                    "",
//	                    JOptionPane.ERROR_MESSAGE);
//	            ex.printStackTrace();
//	        } catch (SQLException ex) {
//	            JOptionPane.showMessageDialog(null,
//	                     "",
//	                    "",
//	                    JOptionPane.ERROR_MESSAGE);
//	            ex.printStackTrace();
//	        }


	    }

	  
	    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	    private void initComponents() {

	        spnlRoleData = new JScrollPane();
	        spnlRoleData1 = new JScrollPane();
	        tblData = new JTable();

	        setPreferredSize(new Dimension(791, 655));

	        tblData.setModel(new DefaultTableModel(
	            new Object [][] {
	                {null, null, null, null},
	                {null, null, null, null},
	                {null, null, null, null},
	                {null, null, null, null}
	            },
	            new String [] {
	                "Title 1", "Title 2", "Title 3", "Title 4"
	            }
	        ));
	        spnlRoleData1.setViewportView(tblData);

	        spnlRoleData.setViewportView(spnlRoleData1);

	        GroupLayout layout = new GroupLayout(this);
	        this.setLayout(layout);
	        layout.setHorizontalGroup(
	            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
	            .addGroup(layout.createSequentialGroup()
	                .addContainerGap()
	                .addComponent(spnlRoleData, GroupLayout.DEFAULT_SIZE, 771, Short.MAX_VALUE)
	                .addContainerGap())
	        );
	        layout.setVerticalGroup(
	            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
	            .addGroup(layout.createSequentialGroup()
	                .addContainerGap()
	                .addComponent(spnlRoleData, GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE)
	                .addContainerGap())
	        );

	        getAccessibleContext().setAccessibleName("List Role");
	    }// </editor-fold>//GEN-END:initComponents
	    // Variables declaration - do not modify//GEN-BEGIN:variables
}
